
using Microsoft.EntityFrameworkCore;
using Shop.Backend.Api.Entity;
using System;
using System.Collections.Generic;
using System.Text.Json;

namespace Shop.Backend.Api.Database
{
    public class ShopDb : DbContext
    {
        public ShopDb(DbContextOptions options) : base(options)
        {

        }
        public DbSet<Goods> Goods { get; set; }
        public DbSet<GoodsBrands> GoodsBrands { get; set; }
        public DbSet<GoodsCategory1> GoodsCategory1 { get; set; }
        public DbSet<GoodsCategory2> GoodsCategory2 { get; set; }
        public DbSet<GoodsCategory3> GoodsCategory3 { get; set; }
        public DbSet<GoodsComments> GoodsComments { get; set; }
        public DbSet<GoodsEvaluates> GoodsEvaluates { get; set; }
        public DbSet<GoodsExpressAddress> GoodsExpressAddress { get; set; }
        public DbSet<GoodsImages> GoodsImages { get; set; }
        public DbSet<GoodsSKU> GoodsSKU { get; set; }
        public DbSet<LikeShops> LikeShops { get; set; }
        public DbSet<Orders> Orders { get; set; }
        public DbSet<ShoppingCarts> ShoppingCarts { get; set; }
        public DbSet<Shops> Shops { get; set; }
        public DbSet<Suppliers> Suppliers { get; set; }

        // //轮播图表
        // public DbSet<PictureInfo> PictureInfo { get; set; }
        public DbSet<Users> Users { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            options.UseSqlServer(@"server=.;database=ShopApp;uid=sa;pwd=123456;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //     modelBuilder.Entity<A>().Property(x => x.Infos)
            //   .HasConversion(x => JsonSerializer.Serialize(x, null),
            //        x => JsonSerializer.Deserialize<List<B>>(x, null));
            //     base.OnModelCreating(modelBuilder);
            // 初始化一个管理员用户 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<Users>().HasData(
                new Users
                {
                    Id = 1,
                    Username = "admin",
                    Password = "113",
                    IsActived = true,
                    IsDeleted = false,
                    UserRole = 1,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    UserPicture = "http://localhost:8080/6.jpg",
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化供应商 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<Suppliers>().HasData(
                new Suppliers
                {
                    Id = 1,
                    FromUsersId = 1,
                    SuppliersName = "就爱供应",
                    SuppliersAddress = "粉刷省粉刷市粉刷县粉刷村10007号",
                    SuppliersPhone = "15647825",
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化品牌 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<GoodsBrands>().HasData(
                new GoodsBrands
                {
                    Id = 1,
                    BrandsName = "就爱爱",
                    BrandDesc = "这是一个全球前十的品牌",
                    BrandLogo = "54656654.jpg",
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化商店 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<Shops>().HasData(
                new Shops
                {
                    Id = 1,
                    ShopName = "就爱商店",
                    SuppliersId = 1,
                    ShopAddress = "就爱省就爱市就爱县就爱村10086号",
                    ShopPhone = "188888",
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化一级分类 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<GoodsCategory1>().HasData(
                new GoodsCategory1
                {
                    Id = 1,
                    CategoryName = "家具",
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化二级分类 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<GoodsCategory2>().HasData(
                new GoodsCategory2
                {
                    Id = 1,
                    CategoryName = "客厅家具",
                    FromCategory1Id = 1,
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
            // 初始化三级分类 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<GoodsCategory3>().HasData(
                new GoodsCategory3
                {
                    Id = 1,
                    CategoryName = "沙发",
                    FromCategory2Id = 1,
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = "种子数据"
                }
            );
            base.OnModelCreating(modelBuilder);
        }

    }


}